﻿using System.Web.Mvc;
using eCommerce.Core;
using eCommerce.Core.Domain.Customers;
using eCommerce.Models.Customers;
using eCommerce.Services.Authentication;
using eCommerce.Services.Customers;
using eCommerce.Services.Pictures;

namespace eCommerce.Controllers
{
    public class CustomerController : BaseController
    {
        private ICustomerService _customerService;
        private IAuthenticationService _authenticationService;
        private IWorkContext _workContext;
        private IPictureService _pictureService;

        public CustomerController(ICustomerService customerService, IAuthenticationService authenticationService, IWorkContext workContext, IPictureService pictureService)
        {
            _customerService = customerService;
            _authenticationService = authenticationService;
            _workContext = workContext;
            _pictureService = pictureService;
        }

        protected bool IsCurrentUserRegistered()
        {
            return _workContext.CurrentCustomer.IsRegistered();
        }

        public ActionResult Setting()
        {
            return View();
        }
   
        //public ActionResult Info()
        //{
        //    if (!IsCurrentUserRegistered())
        //        return new HttpUnauthorizedResult();

        //    var customer = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id);

        //    var model = new CustomerInfoEditModel()
        //        {
        //            Id = _workContext.CurrentCustomer.Id,
        //            NickName = customer.NickName,
        //            Intro = customer.Intro,
        //        };
        //    ViewBag.Model = model;
        //    return View();
        //}


        //public ActionResult Logo()
        //{
        //    var model = new CustomerLogoModel()
        //        {
        //            PictureId = _workContext.CurrentCustomer.CustomerLogoId.HasValue? _workContext.CurrentCustomer.CustomerLogo.PictureId:0,
        //            CustomerLogId = _workContext.CurrentCustomer.CustomerLogoId.HasValue? _workContext.CurrentCustomer.CustomerLogoId.Value: 0,
        //            PictureUrl = _workContext.CurrentCustomer.CustomerLogoId.HasValue? _pictureService.GetPictureUrl(_workContext.CurrentCustomer.CustomerLogo.PictureId,0,true): ConstInfo.DefaultImageUrl,
        //            DemoUrl = ConstInfo.DemoImageUrl,
        //        };
        //    ViewBag.Model = model;
        //    return View();
        //}
      

        public ActionResult Login()
        {
            var model = new LoginModel();
            ViewBag.Model = model;
            return View();
        }

        //public ActionResult Register()
        //{
        //    var model = new RegisterModel();
        //    ViewBag.Model = model;
        //    return View();
        //}

        public ActionResult ChangePassword()
        {
            return View();
        }

        public ActionResult SignOff()
        {
            _authenticationService.SignOut();
            return RedirectToAction("Login");
        }

    }
}
